package com.edu.hre.db.service.impl;
 
import java.util.Collection;
import java.util.List;  
import org.apache.log4j.Logger;  

import com.edu.hre.common.utils.CommonUtils;
import com.edu.hre.db.dao.BaseDao;
import com.edu.hre.db.service.BaseService;
import com.edu.hre.struts.form.recruit.CandidateForm;

public class BaseServiceImpl implements BaseService { 
	
	private final Logger logger = Logger.getLogger(BaseServiceImpl.class);
	private BaseDao baseDao;

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}

	public <T> List<T> getPojos(String colName, int compare, Object colValue, String[] orderBy, Boolean[] desc, int limit, int offset, Class<T> _class){
		try {
			return baseDao.getPojos(colName, compare, colValue, orderBy, desc, limit, offset, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		} 
	}

	public <T> List<T> getPojosAnd(String[] colNames, int[] compares, Object[] colValues, String[] orderBy, Boolean[] desc, int limit, int offset, Class<T> _class){
		try {
			return baseDao.getPojosAnd(colNames, compares, colValues, orderBy, desc, limit, offset, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> List<T> getPojosOr(String[] colNames, int[] compares, Object[] colValues, String[] orderBy, Boolean[] desc, int limit, int offset, Class<T> _class){
		try {
			return baseDao.getPojosOr(colNames, compares, colValues, orderBy, desc, limit, offset, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getPojo(int pId, Class<T> _class){
		try {
			return baseDao.getPojo(pId, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> boolean saveOrUpdate(Collection<T> pojos){
		try {
			return baseDao.saveOrUpdate(pojos);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> boolean saveOrUpdate(T pojo){
		try {
			return baseDao.saveOrUpdate(pojo);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> int sumByColumns(String[] colNames, int[] compares, Object[] colValues, String colSumName, Class<T> _class){
		try {
			return baseDao.sumByColumns(colNames, compares, colValues, colSumName, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return -1;
		}
	}

	public <T> int countByColumns(String[] colNames, int[] compares, Object[] colValues, String colCountName, Class<T> _class){
		try {
			return baseDao.countByColumns(colNames, compares, colValues, colCountName, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return -1;
		}
	}

	public <T> List<T> getPojosIn(String colName, Object[] colValues, String[] orderBy, Boolean[] desc, int limit, int offset, Class<T> _class){
		try {
			return baseDao.getPojosIn(colName, colValues, orderBy, desc, limit, offset, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public int update(String tbName, String[] colNames, Object[] colValues, String[] whereColNames, int[] whereCompares, Object[] whereColValues, String andOr){
		try {
			return baseDao.update(tbName, colNames, colValues, whereColNames, whereCompares, whereColValues, andOr);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return -1;
		}
	}

	public List<Object[]> listArrayObject(String sql, int limit, int offset, Object...params){
		try {
			return baseDao.listArrayObject(sql, limit, offset, params);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getFirstPojo(String colName, int compare, Object colValue, String[] orderBy, Boolean[] desc, int offset, Class<T> _class){
		try {
			return baseDao.getFirstPojo(colName, compare, colValue, orderBy, desc, offset, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getFirstPojoOr(String[] colNames, int[] compares, Object[] colValues, String[] orderBy, Boolean[] desc, int offset, Class<T> _class){
		try {
			return baseDao.getFirstPojoOr(colNames, compares, colValues, orderBy, desc, offset, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getFirstPojoAnd(String[] colNames, int[] compares, Object[] colValues, String[] orderBy, Boolean[] desc, int offset, Class<T> _class){
		try {
			return baseDao.getFirstPojoAnd(colNames, compares, colValues, orderBy, desc, offset, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getFirstPojoIn(String colName, Object[] colValues, String[] orderBy, Boolean[] desc, int offset, Class<T> _class){
		try {
			return baseDao.getFirstPojoIn(colName, colValues, orderBy, desc, offset, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> boolean deletePojo(T pojo){
		try {
			return baseDao.deletePojo(pojo);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> boolean deletePojos(Collection<T> pojos){
		try {
			return baseDao.deletePojos(pojos);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> int deletePojos(String sqlCommand, Object... params){
		try {
			return baseDao.deletePojos(sqlCommand, params);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return -1;
		}
	}

	public <T> boolean deleteFirstPojo(String colName, int compare,
			Object colValue, String[] orderBy, Boolean[] desc, int offset, Class<T> _class) {
		try {
			return baseDao.deleteFirstPojo(colName, compare, colValue, orderBy, desc, offset, _class);
		} catch (Exception e) { 
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> boolean deleteFirstPojo(int pId, Class<T> _class)  {
		try {
			return baseDao.deleteFirstPojo(pId, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> boolean save(Collection<T> pojos) {
		try {
			return baseDao.save(pojos);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> boolean save(T pojo) {
		try {
			return baseDao.save(pojo);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> boolean update(Collection<T> pojos) {
		try {
			return baseDao.update(pojos);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public <T> boolean update(T pojo) {
		try {
			return baseDao.update(pojo);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return false;
		}
	}

	public List<CandidateForm> listRecommendedCandidates(final String procedureName, Object[] params) {
		try {
			return baseDao.listRecommendedCandidates(procedureName, params);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> int sumByColumns(String colNames, int compares, Object colValues, String colSumName, Class<T> _class) {
		try {
			return baseDao.sumByColumns(colNames, compares, colValues, colSumName, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return -1;
		}
	}

	public <T> int countByColumns(String colNames, int compares, Object colValues, String colCountName, Class<T> _class) {
		try {
			return baseDao.countByColumns(colNames, compares, colValues, colCountName, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return -1;
		}
	}

	public <T> List<T> getAllPojos(Class<T> _class) {
		try {
			return baseDao.getPojos(null, -1, null, null, null, 0, 0, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> List<T> getAllPojos(String[] orderBy, Boolean[] desc, Class<T> _class) {
		try {
			return baseDao.getPojos(null, -1, null, orderBy, desc, 0, 0, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> List<T> getPojos(String colName, int compare, Object colValue, Class<T> _class) {
		try {
			return baseDao.getPojos(colName, compare, colValue, null, null, 0, 0, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getFirstPojo(String colName, int compare, Object colValue, Class<T> _class) {
		try {
			return baseDao.getFirstPojo(colName, compare, colValue, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getFirstPojoOr(String[] colNames, int[] compares, Object[] colValues, Class<T> _class) {
		try {
			return baseDao.getFirstPojoOr(colNames, compares, colValues, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getFirstPojoAnd(String[] colNames, int[] compares, Object[] colValues, Class<T> _class) {
		try {
			return baseDao.getFirstPojoAnd(colNames, compares, colValues, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> T getFirstPojoIn(String colName, Object[] colValues, Class<T> _class) {
		try {
			return baseDao.getFirstPojoIn(colName, colValues, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return null;
		}
	}

	public <T> int sumByColumnsOr(String[] colNames, int[] compares, Object[] colValues, String colSumName, Class<T> _class) throws Exception {
		try {
			return baseDao.sumByColumnsOr(colNames, compares, colValues, colSumName, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return 0;
		}
	}

	public <T> int countByColumnsOr(String[] colNames, int[] compares, Object[] colValues, String colCountName, Class<T> _class) {
		try {
			return baseDao.countByColumnsOr(colNames, compares, colValues, colCountName, _class);
		} catch (Exception e) {
			CommonUtils.println(CommonUtils.getStackTraceException(e));
			return 0;
		}
	}
}
